package com.lyf.language.learn.atsgg.network;

import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * @AUTHOR LYF
 * @DATE 2022/6/4
 * @VERSION 1.0
 * @DESC
 */
public class UrlTests {
    @Test
    public void test1() throws IOException {
        URL url  = new URL("http://122.96.151.110");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        System.out.println(connection.getResponseCode()+":"+connection.getContent().toString());

        InputStream inputStream  = connection.getInputStream();
        byte[] bytes = new byte[1024];
        int len;
        System.out.println(connection.getResponseMessage());

        while ((len = inputStream.read(bytes))!=-1){
            System.out.println(new String(bytes,0,bytes.length));
        }

    }

}
